@echo off
setlocal enabledelayedexpansion

:: 定义源目录数组
set "sourceDirs[0]=D:\workspace\ccbPortal\ccb-portal"
set "sourceDirs[1]=D:\workspace\e_code_through"
set "sourceDirs[2]=D:\workspace\ccbPortal\ccb-portal"
set "sourceDirs[3]=D:\workspace\e_code_through"
set "sourceDirs[4]=D:\workspace\xyemt"
set "sourceDirs[5]=D:\workspace\ccbService\ccbService"
set "sourceDirs[6]=D:\workspace\documents\emt"
set "sourceDirs[7]=D:\workspace\scanresult"
set "sourceDirs[8]=D:\workspace\hallofpay-NewVersion"
set "sourceDirs[9]=D:\workspace\hallpay\hallofpay-old"
set "sourceDirs[10]=D:\workspace\ccb-app-metro2\ccb-app-metro"
set "sourceDirs[11]=D:\workspace\health_check"
set "sourceDirs[12]=D:\workspace\access_management\emp-app-guajian"
set "sourceDirs[13]=D:\workspace\draglowercode\vue2d\vue2d"
set "sourceDirs[14]=D:\WeChatFile\WeChat Files\hiluzy\FileStorage\File\2024-07\xydzk 2\xydzk"

:: 定义目标根目录
set "targetRootDir=G:\workspace\20241210"

:: 遍历数组中的每个源目录并复制文件
for /L %%i in (0,1,1) do (
    set "sourceDir=!sourceDirs[%%i]!"
    if exist "!sourceDir!" (
        echo Copying from "!sourceDir!"
        
        :: 获取源目录的名称
        for %%p in ("!sourceDir!") do set "sourceDirName=%%~nxp"
        
        :: 创建目标目录如果它不存在
        set "targetDir=!targetRootDir!\!sourceDirName!"
        if not exist "!targetDir!" mkdir "!targetDir!"
        
        :: 复制文件和目录到目标目录
        xcopy "!sourceDir!\*" "!targetDir!" /E /I /Y
    ) else (
        echo Source directory "!sourceDir!" does not exist.
    )
)

echo Files copied successfully.
endlocal